package com.niconicod.ofb.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.utils.ScreenUtils;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.niconicod.ofb.OfbGame;

public class MainMenuScreen implements Screen {

    private OfbGame ofbGame;
    private Stage stage;

    public MainMenuScreen(OfbGame ofbGame) {
        this.ofbGame = ofbGame;
    }

    @Override
    public void show() {
        float aspectRatio = (float) Gdx.graphics.getWidth() / Gdx.graphics.getHeight();
        stage = new Stage(new FitViewport(50f * aspectRatio, 50f));
        stage.setDebugAll(true);

        TextureAtlas atlas = new TextureAtlas("uiskin.atlas");

        FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("garuda.ttf"));

        FreeTypeFontParameter parameter = new FreeTypeFontParameter();
        parameter.size = Gdx.graphics.getHeight() / 10;

        BitmapFont font = generator.generateFont(parameter);
        font.getData().setScale(50f / Gdx.graphics.getHeight());

        LabelStyle labelStyle = new LabelStyle();
        labelStyle.font = font;

        Label label = new Label("Press space to start the game!", labelStyle);
        stage.addActor(label);
        System.out.println();
    }

    @Override
    public void render(float delta) {
        ScreenUtils.clear(0, 0, 0, 0);
        stage.act(delta);
        stage.draw();
        if (Gdx.input.isKeyPressed(Input.Keys.SPACE)){
            ofbGame.startGame();
        }
    }

    @Override
    public void resize(int width, int height) {
        stage.getViewport().update(width, height, true);
    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {

    }
}
